import { AutoCorrectListType, AutoCorrectTrunksType, BaseQuestionType, UnknownItemType } from '@/types/know/know';
import { create } from 'zustand';


interface KnowledgeState {
  unknownItem: UnknownItemType;
  setUnknownItem: (value: UnknownItemType) => void;
  dislikeItem: BaseQuestionType;
  setDislikeItem: (value: BaseQuestionType) => void;
  listLength: number;
  setListLength: (value: number) => void;
  //敏感词
  sensitiveWord: AutoCorrectListType[];
  setSensitiveWord: (value: AutoCorrectListType[]) => void;
  sensitiveTrunks: AutoCorrectTrunksType[];
  setSensitiveTrunks: (value: AutoCorrectTrunksType[]) => void;
  //错别字
  wronglyList: AutoCorrectListType[];
  setWronglyList: (value: AutoCorrectListType[]) => void;
  wronglyTrunks: AutoCorrectTrunksType[];
  setWronglyTrunks: (value: AutoCorrectTrunksType[]) => void;

  //共享trunks
  trunksList: AutoCorrectTrunksType[];
  setTrunksList: (value: AutoCorrectTrunksType[]) => void;
  datasList: AutoCorrectListType[];
  setDatasList: (value: AutoCorrectListType[]) => void;

  // 预取数据缓存
  prefetchedWrongly?: {
    collectionId: string;
    appId: string;
    auto_correct_pairs_with_count: AutoCorrectListType[];
    trunks: AutoCorrectTrunksType[];
  } | null;
  setPrefetchedWrongly: (value: KnowledgeState['prefetchedWrongly']) => void;

  prefetchedSensitive?: {
    collectionId: string;
    appId: string;
    all_sensitive_words_with_count: AutoCorrectListType[];
    trunks: AutoCorrectTrunksType[];
  } | null;
  setPrefetchedSensitive: (value: KnowledgeState['prefetchedSensitive']) => void;

  prefetchedRepetition?: {
    collectionId: string;
    appId: string;
    data: any;
  } | null;
  setPrefetchedRepetition: (value: KnowledgeState['prefetchedRepetition']) => void;
}
export const useKnowledgeStore = create<KnowledgeState>((set) => ({
  unknownItem: {
    keyQuestionQaId: '',
    keyQuestionText: '',
    clusterItems: [],
    appId: '',
    clusterSize: 0,
    id: '',
    mentionedTimes: 0,
    time: ''
  },
  dislikeItem: {
    _id: '',
    qaId: '',
    keyAnswerId: '',
    keyQuestionId: '',
    feedback: '',
    keyQuestionAnswer: '',
    keyQuestionText: '',
    keyQuestionChatId: '',
    status: 0,
    updateTime: '',
    roleName: '',
    annoId: '',
    annoQ: '',
    annoA: '',
    category: ''
  },
  listLength: 0,
  trunksList: [],
  setTrunksList: (value) => set(() => ({ trunksList: value })),
  datasList: [],
  setDatasList: (value) => set(() => ({ datasList: value })),


  sensitiveWord: [],
  setSensitiveWord: (value) => set(() => ({ sensitiveWord: value })),
  sensitiveTrunks: [],
  setSensitiveTrunks: (value) => set(() => ({ sensitiveTrunks: value })),

  wronglyList: [],
  setWronglyList: (value) => set(() => ({ wronglyList: value })),
  wronglyTrunks: [],
  setWronglyTrunks: (value) => set(() => ({ wronglyTrunks: value })),

  // 预取数据缓存（默认 null）
  prefetchedWrongly: null,
  setPrefetchedWrongly: (value) => set(() => ({ prefetchedWrongly: value })),
  prefetchedSensitive: null,
  setPrefetchedSensitive: (value) => set(() => ({ prefetchedSensitive: value })),
  prefetchedRepetition: null,
  setPrefetchedRepetition: (value) => set(() => ({ prefetchedRepetition: value })),

  setUnknownItem: (value) => set(() => ({ unknownItem: value })),
  setDislikeItem: (value) => set(() => ({ dislikeItem: value })),
  setListLength: (value) => set(() => ({ listLength: value })),
}));
